<div class="sidebar">

  <script type="text/javascript">
    $(document).ready(function(){
      
      var sstopl   = $(".widget:last").position().top;
      var scroH    = $(this).scrollTop();
      var sstoplW  = $(".widget:first").width();
      var winWidth = $(document).width();
      
      $(document).scroll(function(){
        if(winWidth>600){
          scroH = $(this).scrollTop()+50+50;
          sstoplW = $(".widget:first").width();
          winWidth = $(document).width();
          if(scroH > sstopl) {
            if ($("#wpadminbar").height()!=null){
              $(".widget:last").css({"position":"fixed","top":72+50}).width(sstoplW); 
            }else{
              $(".widget:last").css({"position":"fixed","top":50+50}).width(sstoplW); 
            }
          }else{
            $(".widget:last").css({"position":"static"});
          }
        }else{
          winWidth = $(document).width();
          $(".widget:last").css({"position":"static"});
          //if[end]
        }
      });
    });
  </script>

  <?php if ( is_active_sidebar( 'sidebar-1' ) ) : ?>
		<div id="secondary" class="widget-area" role="complementary">
			<?php dynamic_sidebar( 'sidebar-1' ); ?>
		</div>
  <?php endif; ?>
  
</div>

<script type="text/javascript">
  jQuery("#loading").animate({width:"50%"},500);
</script>
